package com.itheima.test02;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Test07 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student s1 = new Student("张三", 43);
        Student s2 = new Student("李四", 23);
        Student s3 = new Student("王五", 33);
        Student s4 = new Student("贾六", 25);
        Student s5 = new Student("田七", 19);
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.add(s5);

        Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student s1, Student s2) {
                int num1= s1.getAge()-s2.getAge();
                int num2 = num1==0?s1.getName().compareTo(s2.getName()):num1;
                return num2;
            }
        });
        for (Student s : list) {
            System.out.println(s);
        }

    }
}
